import { INPUT_CONSTRAINTS } from '@/pages/workflow/components/InspectData'
import TextareaWithParamsV2 from '@/pages/workflow/components/TextareaWithParamsV2'
import { useEffect, useState } from 'react'

/* 系统提示词 */
export default function UserCallWordCont({ info, sourceOptions, editData }) {
  const [loadContent, setLoadContent] = useState(false)
  const [value, setValue] = useState('')

  useEffect(() => {
    setValue(info.callWord)
  }, [info])

  useEffect(() => {
    setLoadContent(true)
  }, [sourceOptions])
  const showErrorInfo = value => {
    if (!value || !value.trim()) {
      return <span className="custom-params-invalid">提示词不能为空</span>
    }

    if (value.length > INPUT_CONSTRAINTS.AGENT_RECOVERY_MAX_LENGTH) {
      return (
        <span className="custom-params-invalid">{`提示词长度不能大于${INPUT_CONSTRAINTS.AGENT_RECOVERY_MAX_LENGTH}个字符`}</span>
      )
    }
  }
  return (
    <div className="flexCol">
      {/* <CustomTextArea
        value={value}
        onChange={e => {
          setValue(e.target.value)
          editData({
            callWord: e.target.value
          })
        }}
        placeholder="用于大模型节点的提示词，可以用{{}}引入变量"
        rows={4}
        maxLength={INPUT_CONSTRAINTS.CALL_WORD_MAX_LENGTH}
      ></CustomTextArea> */}
      {loadContent && (
        <>
          <TextareaWithParamsV2
            placeholder="填写系统提示词，输入'{' 选择变量进行插入。"
            value={value}
            onChange={msg => {
              setValue(msg)
              editData({
                callWord: msg
              })
              // handleOutputTextChange(msg)
            }}
            error={!value?.length || !value.trim() || value?.length > INPUT_CONSTRAINTS.CALL_WORD_MAX_LENGTH}
            citeOptions={sourceOptions}
          />
          {showErrorInfo(value)}
        </>
      )}
    </div>
  )
}
